package com.ruoyi.system.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.core.domain.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.Date;

/**
 * 健康数据对象 sys_health_data
 *
 * @author ruoyi
 */
@Data
@EqualsAndHashCode(callSuper = true)
@ApiModel("健康数据")
public class SysHealthData extends BaseEntity {
    private static final long serialVersionUID = 1L;

    /**
     * 数据ID
     */
    @ApiModelProperty(value = "数据ID", required = true)
    private Long id;

    /**
     * 设备ID
     */
    @ApiModelProperty(value = "设备ID", required = true)
    @NotBlank(message = "设备ID不能为空")
    @Size(max = 64, message = "设备ID不能超过64个字符")
    private Long deviceId;

    /**
     * 用户ID
     */
    @ApiModelProperty(value = "用户ID")
    @Size(max = 64, message = "用户ID不能超过64个字符")
    private Long userId;

    /**
     * 请求ID
     */
    @ApiModelProperty(value = "请求ID")
    private String requestId;

    /**
     * 心率
     */
    @ApiModelProperty(value = "心率", required = true)
    @NotBlank(message = "心率不能为空")
    private String heartRate;

    /**
     * 血压
     */
    @ApiModelProperty(value = "血压", required = true)
    @NotBlank(message = "血压不能为空")
    private String bloodPressure;

    /**
     * 血氧
     */
    @ApiModelProperty(value = "血氧", required = true)
    @NotBlank(message = "血氧不能为空")
    private String bloodOxygen;

    /**
     * 更新时间戳
     */
    @ApiModelProperty(value = "更新时间戳", required = true)
    @NotNull(message = "更新时间戳不能为空")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date updateTime;

    /**
     * 特征类型枚举
     */
    @Getter
    public enum FeatureType {
        OFFLINE(0L, "在离线"),
        HEART_RATE(1L << 1, "心率"),
        BLOOD_PRESSURE(1L << 2, "血压"),
        BLOOD_OXYGEN(1L << 3, "血氧"),
        SLEEP(1L << 4, "睡眠"),
        TEMPERATURE(1L << 5, "体温"),
        LOCATION(1L << 7, "定位"),
        BATTERY(1L << 8, "电量"),
        CONTINUOUS_HEART_RATE(1L << 13, "连续心率"),
        HRV(1L << 15, "HRV"),
        URIC_ACID(1L << 18, "尿酸"),
        BLOOD_GLUCOSE(1L << 19, "血糖"),
        RESPIRATORY_RATE(1L << 20, "呼吸率"),
        PRESSURE(1L << 25, "压力"),
        BLOOD_LIPIDS(1L << 26, "血脂"),
        PPG_DATA(1L << 28, "脉搏波PPG数据"),
        FATIGUE(1L << 29, "疲劳度"),
        LASER_THERAPY(1L << 30, "激光理疗");

        private final Long value;
        private final String description;

        FeatureType(Long value, String description) {
            this.value = value;
            this.description = description;
        }

        public static FeatureType fromValue(Long value) {
            for (FeatureType type : FeatureType.values()) {
                if (type.value.equals(value)) {
                    return type;
                }
            }
            return null;
        }
    }
}